! To modify the atom, bond, angle and/or dihedral type id
subroutine modify(info)
use molecule
implicit none
   !-------------------------------------------------------------------------
   integer, intent(in) :: info
   !-------------------------------------------------------------------------
   character (len=256) :: oneline
   character (len=10)  :: chartype(4)=(/"atomic  ","bond    ","angle   ","dihedral"/)
   integer             :: indx, newid, ioerr, nmax
   !-------------------------------------------------------------------------
   call GetNmax()
   if ( nmax.lt.1 ) return
   !
   write(*, '(/,10x,"Your chose to modify some type IDs. Follow the instructions")')
   write(*, '(10x,"below; you can always exit by enter an empty line. If a new ID")')
   write(*, '(10x,"of zero is assigned, the whole type of atom/bond/angle/dihedral")')
   write(*, '(10x,"will be skipped in the output.",/)')
   !
   do while ( .true. )
      write(*,'(10x,"Please input the ",A," type index and new ID pair: ",$)') trim(chartype(info))
      read(*,'(A)', iostat=ioerr) oneline
      if ( ioerr.ne.0 ) exit
      read(oneline, *, iostat=ioerr) indx, newid
      if ( ioerr.ne.0.or.indx.le.0 ) exit
      call applynewid()
   enddo
   !
return
contains
   subroutine GetNmax( )
   implicit none
      !-------------------------------------------------------------------------
      select case ( info )
      case ( 1 )
         if (.not.allocated(typeid) ) then
            nmax = 0
         else 
            nmax = size(typeid)
         endif
      case ( 2 )
         if (.not.allocated(bondid) ) then
            nmax = 0
         else
            nmax = size(bondid)
         endif
      case ( 3 )
         if (.not.allocated(angleid) ) then
            nmax = 0
         else
            nmax = size(angleid)
         endif
      case ( 4 )
         if (.not.allocated(dihedid) ) then
            nmax = 0
         else
            nmax = size(dihedid)
         endif
      end select
      !-------------------------------------------------------------------------
   end subroutine GetNmax

   subroutine applynewid( )
   implicit none
      !-------------------------------------------------------------------------
      select case ( info )
      case ( 1 )
         if ( indx.le.nmax ) typeid(indx)  = newid
      case ( 2 ) 
         if ( indx.le.nmax ) bondid(indx)  = newid
      case ( 3 )
         if ( indx.le.nmax ) angleid(indx) = newid
      case ( 4 )
         if ( indx.le.nmax ) dihedid(indx) = newid
      end select
      !-------------------------------------------------------------------------
   end subroutine applynewid
end subroutine
